require( '$d/css/common.less' );
require( './style.less' );
define( [
  'require',
  'jquery',
  'constants',
  'message',
  'header',
  'nav',
  'plat_public',
  'bootstrap',
  'selector',
  'bigwe_utils',
  'fullcalendar',
  'mpnewsChoose',
  'videoChoose',
  'imgChoose',
  'unauthor',
  'api',
  'imgUploader',
  'videoUploader',
  'soundUploader',
  'soundChoose',
  './timed_send',
], function( require, $, c, message ) {
  var
    mpnewsChoose = require( 'mpnewsChoose' ),
    imgChoose = require( 'imgChoose' ),
    videoChoose = require( 'videoChoose' ),
    soundChoose = require( 'soundChoose' ),
    bwAuthor = require( 'unauthor' ),
    InterFace = require( 'api' ),
    util = require( 'bigwe_utils' ),
    imgupload = require('imgUploader'),
    videoupload = require('videoUploader'),
    soundupload = require('soundUploader'),
    definedCallback = require('plat_public'),
    showTime = 3e3,
    timing_list = require( './timed_send' );

  var constants = require( 'constants' );

  /* ====== * 容器选择器 * ====== */
  var content = $( '.main_left' ),
    pack = content.find( '.mass_editing' ),
    type_nav = pack.find( '.type_btn_list' ),
    mass_content = pack.find( '.mass_content' );

  /* ====== * 公用变量 * ====== */
  var acount_info,
    first_time = true,
    send_data = {
      index: 0,
    };
  var eitd_send = {
    first: false,
  };
  /* ====== * 平台,公众号 * ====== */
  var _plat = ( util.getUrlParam( 'send_pltfm' ) == 'weixin' ) ? 'wechat' : util.getUrlParam( 'send_pltfm' );
  if ( util.getUrlParam( 'mid' ) ) {
    eitd_send.first = true;
    $.ajax( {
      type: 'post',
      url: InterFace.SENDING.GET_TIMERS,
      data: {
        app: _plat,
        mid: util.getUrlParam( 'mid' ),
      },
      success: function( data ) {
        var data = typeof data === 'string' ? $.parseJSON( data ) : data;
        var send_info = {};
        if ( data.ret != 0 ) {
          message.showWarning( data.msg, message.showTime );
          eitd_send.first = false;
          public_information();
          return;
        }
        if ( util.getUrlParam( 'send_pltfm' ) == 'weixin' ) {
          var js_app = typeof data.data.js_app === 'string' ? $.parseJSON( data.data.js_app ) : data.data.js_app;
          var js_content = typeof data.data.js_content === 'string' ? $.parseJSON( data.data.js_content ) : data.data.js_content;
          var texts = typeof js_content.texts === 'string' ? $.parseJSON( js_content.texts ) : js_content.texts;
          send_info.msg_type = data.data.msg_type_cd;
          send_info.apid = js_app.app_id;
          send_info.id = data.data.id;
          eitd_send.time = data.data.appointment_time;

          if ( data.data.msg_type_cd == 'mpnews' ) {
            eitd_send.article_group = data.data.res_id;
            eitd_send.articles = js_content;
          } else if ( data.data.msg_type_cd == 'text' ) {
            mass_content.find( ".text_edit.text_maxlen" ).val( texts[ 0 ].title );
          } else if ( data.data.msg_type_cd == 'image' ) {
            eitd_send.image_name = texts[ 0 ].title;
            eitd_send.image_id = data.data.res_id;
            eitd_send.image = js_content.cover_img_url;
          } else if ( data.data.msg_type_cd == 'voice' ) {
            eitd_send.voice_id = data.data.res_id;
            eitd_send.address = js_content.cover_img_url;
            eitd_send.title = texts[ 0 ].title;
            eitd_send.length = texts[ 0 ].length;
          } else if ( data.data.msg_type_cd == 'video' ) {
            eitd_send.video_id = data.data.res_id;
            eitd_send.address = js_content.cover_img_url;
            eitd_send.title = texts[ 0 ].title;
          }
        } else if ( util.getUrlParam( 'send_pltfm' ) == 'sina' ) {
          send_info.msg_type = data.data.msgtype;
          send_info.apid = data.data.uid;
          send_info.id = data.data.id;
          eitd_send.time = data.data.send_time;
          if ( send_info.msg_type == 'mpnews' ) {
            var js_content = typeof data.data.js_content === 'string' ? $.parseJSON( data.data.js_content ) : data.data.js_content;
            eitd_send.article_group = data.data.article_group_cd;
            eitd_send.articles = js_content;
          } else if ( send_info.msg_type == 'text' ) {
            mass_content.find( ".text_edit.text_maxlen" ).val( data.data.title );
          } else if ( send_info.msg_type == 'image' ) {
            mass_content.find( '.sina .text_edit' ).val( data.data.title )
            eitd_send.image_name = data.data.title;
            eitd_send.image = data.data.original_pic;
          }
          eitd_send.sina_type = data.data.sina_type;
        } else if ( util.getUrlParam( 'send_pltfm' ) == 'toutiao' ) {
          send_info.msg_type = data.data.type;
          send_info.apid = data.data.uid;
          send_info.id = data.data.id;
          eitd_send.time = data.data.send_time;
          if ( send_info.msg_type == 'mpnews' ) {
            var js_content = typeof data.data.js_content === 'string' ? $.parseJSON( data.data.js_content ) : data.data.js_content;
            eitd_send.article_group = data.data.group_cd;
            eitd_send.articles = js_content;
          } else if ( send_info.msg_type == 'video' ) {
            eitd_send.address = data.data.content;
            eitd_send.title = data.data.title;
          }
        }
        pack.find( '.send_out' ).data( 'edittype', send_info.msg_type ).attr( 'data-edittype', send_info.msg_type );
        switch ( send_info.msg_type ) {
          case ( 'mpnews' ):
            type_nav.find( "a" ).eq( 0 ).trigger( 'click' );
            break;
          case ( 'text' ):
            type_nav.find( "a" ).eq( 1 ).trigger( 'click' );
            break;
          case ( 'image' ):
            type_nav.find( "a" ).eq( 2 ).trigger( 'click' );
            break;
          case ( 'voice' ):
            type_nav.find( "a" ).eq( 3 ).trigger( 'click' );
            break;
          case ( 'video' ):
            type_nav.find( "a" ).eq( 4 ).trigger( 'click' );
            break;
        }

        $( '.delete_plan' ).removeClass( 'hide' ).attr( 'data-id', send_info.id );
        $( '.send_out' ).attr( 'data-modify', send_info.id );
        if ( send_info.msg_type != 'text' ) {
          add_show( eitd_send, send_info.msg_type );
        }
        public_information( send_info.apid );
      }
    } );
  } else {
    public_information();
  }


  function public_information( apid ) {
    definedCallback.init( {
      platform: [ 'weixin', 'sina', 'toutiao' ],
      defaultPlatform: util.getUrlParam( 'send_pltfm' ) || '',
      defaultPublic: apid || '',
      callback: initialize
    } );
  }

  /* ====== * 初始化加载 * ====== */
  function initialize( data, platform ) {
    acount_info = data;
    send_data.pt = platform;
    pack.addClass( 'hide' );
    content.find( '.toutiao_prompt' ).addClass( 'hide' );

    if ( acount_info ) {
      if ( platform == 'toutiao' ) {
        content.find( '.toutiao_prompt' ).removeClass( 'hide' );
        if ( !$( '#toutiao_mpnews .mask' ).hasClass( 'active' ) && $( '#toutiao_mpnews .toutiao_mpnew_list' ).children().length > 1 ) {
          $( '#toutiao_mpnews' ).modal( 'show' );
        }
      }
      pack.removeClass( 'hide' );
      if ( first_time ) {
        nav_box();
        multi_platform();
      }
      edit_reset( platform );
      if ( first_time ) {
        $.ajax( {
          type: 'post',
          url: InterFace.SENDING.MATE_TOPIC,
          data: {},
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret == 0 ) {
              pack.find( '.hotspot_matching' ).removeClass( 'hide' ).find( 'p' ).html( data.data );
            }
          }
        } )

        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.SENDING.BIGWE_SDK,
          success: function( data ) {
            $( '#invitation_link' ).val( data.data.url )
            $( '#invitation_code' ).val( data.data.appkey )
          }
        } );
        if ( eitd_send.first ) {
          pack.find( ".nav_box li" ).eq( 1 ).trigger( 'click' );
        }
        if ( util.getUrlParam( 'article_group' ) )
          initial_send_cont( util.getUrlParam( 'article_group' ) );
        if ( util.getUrlParam( 'pic_cd' ) ) {
          type_nav.find( 'a' ).eq( 2 ).click();
          $.ajax( {
            type: 'post',
            url: InterFace.SEARCH.GET_IMG_INFO,
            data: {
              cd: util.getUrlParam( 'pic_cd' )
            },
            success: function( data ) {
              var data = typeof data === 'string' ? $.parseJSON( data ) : data;
              if ( data.ret == 0 ) {
                add_show( data.data, 'image' );
              }
            }
          } )
        }
        if ( util.getUrlParam( 'pid' ) ) {
          type_nav.find( 'a' ).eq( 2 ).click();
          $.ajax( {
            type: 'get',
            url: InterFace.SENDING.GET_IMG_INFO,
            data: {
              pid: util.getUrlParam( 'pid' )
            },
            success: function( data ) {
              var data = typeof data === 'string' ? $.parseJSON( data ) : data;
              if ( data.ret == 0 ) {
                add_show( data.data, 'image' );
              }
            }
          } )
        }
      }
      first_time = false;
    }
  }

  function initial_send_cont( id ) {
    if ( util.getUrlParam( 'edit_sign' ) && acount_info.verify_type_info == 0 )
      pack.find( ".nav_box li:nth-child(2)" ).trigger( 'click' );
    $.ajax( {
      type: 'get',
      url: InterFace.SENDING.GET_NEWS_BYGROUP,
      data: {
        article_group: id,
      },
      success: function( data ) {
        var data = typeof data === 'string' ? $.parseJSON( data ) : data;
        if ( data.ret == 0 ) {
          add_show( data.data, 'mpnews' );
        } else {
          message.showWarning( data.msg, showTime );
        }
      }
    } )
  }

  pack.find( '.hotspot_matching' ).on( 'click', 'span', function() {
    $( this ).parent().addClass( 'hide' );
    if ( !eitd_send.first ) {
      eitd_send.sina_type = '';
    }
  } )

  pack.find( '.hotspot_matching' ).on( 'click', 'button', function() {
    $( this ).parent().addClass( 'hide' );
    $.ajax( {
      type: 'post',
      url: InterFace.SENDING.CLOSE_MATE,
    } )
  } )

  /* ====== * 可分发内容类型重置 * ====== */
  function edit_reset( pt ) {
    pack.find( '.mass_select' ).removeClass( 'hide' );
    pack.find( '.mass_select' ).children().not( ':first' ).addClass( 'hide' );
    type_nav.find( 'a' ).removeClass( 'hide' );
    pack.find( '.mass_once' ).removeClass( 'hide' );

    if ( pack.find( ".nav_box > li:nth-child(2)" ).is( ':hidden' ) ) {
      pack.find( ".nav_box > li:nth-child(2)" ).removeClass( 'hide' );
    }
    if ( pt == 'weixin' ) {
      if ( !eitd_send.first ) {
        type_nav.find( "a:first" ).trigger( 'click' );
        pack.find( '.send_out' ).data( 'edittype', 'mpnews' ).attr( 'data-edittype', 'mpnews' );
      }
      if ( acount_info.verify_type_info == '-1' ) {
        if ( !!pack.find( 'li.back' ).position().left ) {
          pack.find( ".nav_box li:first-child" ).trigger( 'click' );
        }
        pack.find( ".nav_box > li:nth-child(2)" ).addClass( 'hide' );
        type_nav.find( 'a:last-child,a:nth-child(4)' ).addClass( 'hide' );
        pack.find( '.mass_once' ).addClass( 'hide' );
      } else {
        pack.find( ".nav_box > li:nth-child(2)" ).removeClass( 'hide' );
      }
      mass_content.find( 'li:nth-child(3)' ).find( '.add_content.sina' ).addClass( 'hide' );
      if ( mass_content.find( 'li:nth-child(3) > div' ).hasClass( 'add_show' ) ) {
        mass_content.find( 'li:nth-child(3) > .add_show' ).removeClass( 'hide' );
      } else {
        mass_content.find( 'li:nth-child(3)' ).find( '.add_content.weixin' ).removeClass( 'hide' );
      }
      pack.find( '.mass_select .user_group' ).removeClass( 'hide' );
      if ( send_data.index == 0 ) {
        pack.find( '.mass_button > button.send_out' ).text( '分发' );
      } else {
        pack.find( '.mass_select .sel_time' ).removeClass( 'hide' );
        pack.find( '.mass_button > button.send_out' ).text( '保存此消息' );
      }
      mass_content.find( '.text_maxlen' ).prop( 'maxlength', '600' );
      mass_content.find( '.text_count_maxlen' ).text( '600' );
      weixin_group( acount_info.app_id );
    } else if ( pt == 'sina' ) {
      mass_content.find( 'li:nth-child(3)' )
        .find( '.add_content.weixin' ).addClass( 'hide' )
        .siblings( '.add_content.sina' ).removeClass( 'hide' );
      mass_content.find( 'li:nth-child(3) > .add_show' ).addClass( 'hide' );
      if ( eitd_send.sina_type == 'message' ) {
        type_nav.find( 'a' ).not( ':nth-child(1),:nth-child(2)' ).addClass( 'hide' );
        sina_destina( '1' );
        pack.find( '.mass_select .sina_user_group,.mass_select .send_destina' ).removeClass( 'hide' );
      } else {
        type_nav.find( 'a' ).not( ':nth-child(2),:nth-child(3)' ).addClass( 'hide' );
        sina_destina( acount_info.verified );
        pack.find( '.mass_select .sina_visible,.mass_select .send_destina' ).removeClass( 'hide' );
      }
      if ( !eitd_send.first ) {
        type_nav.find( "a:nth-child(2)" ).trigger( 'click' );
        pack.find( '.send_out' ).data( 'edittype', 'text' ).attr( 'data-edittype', 'text' );
      }
      mass_content.find( '.text_maxlen' ).prop( 'maxlength', '140' );
      mass_content.find( '.text_count_maxlen' ).text( '140' );
      if ( send_data.index == 0 ) {
        pack.find( '.mass_button > button.send_out' ).text( '发布' );
      } else {
        pack.find( '.mass_select .sel_time' ).removeClass( 'hide' );
        pack.find( '.mass_button > button.send_out' ).text( '保存此消息' );
      }
    } else if ( pt == 'toutiao' ) {
      if ( !eitd_send.first ) {
        type_nav.find( "a:first" ).trigger( 'click' );
        pack.find( '.send_out' ).data( 'edittype', 'mpnews' ).attr( 'data-edittype', 'mpnews' );
      }
      type_nav.find( 'a' ).not( ':first, :last' ).addClass( 'hide' );
      if ( send_data.index == 0 ) {
        pack.find( '.mass_select' ).addClass( 'hide' );
        pack.find( '.mass_button > button.send_out' ).text( '分发' );
      } else {
        pack.find( '.mass_select .sel_time' ).removeClass( 'hide' );
        pack.find( '.mass_button > button.send_out' ).text( '保存此消息' );
      }
    }
    pack.find( ".selectpicker" ).selectpicker( {
      size: 8,
      dropupAuto: false
    } );
    pack.find( '.multi_push .acount_info' ).removeClass( 'acount_choice' );

    if ( multi_push.find( '#male' ).is( ':checked' ) ) {
      push_acount();
    }
    if ( send_data.index == 1 ) {
      trip_ajax( send_data );
    }
  }

  /* ====== * 用户分组 * ====== */
  function weixin_group( appid ) {
    $.post( InterFace.SENDING.GET_USER_GROUP, {
      app_id: appid,
      done: 'group'
    }, function( data ) {
      var ht = '';
      var json = typeof data === 'string' ? $.parseJSON( data ).data : data.data;
      ht += '<option>全部用户</option>';
      if ( json.length > 0 ) {
        for ( var i in json ) {
          if ( json.group_id != 1 ) {
            ht += '<option value="' + json[ i ].group_id + '">' + json[ i ].group_name + '</option>';
          }
        }
      }
      pack.find( '#user_group' ).empty().append( ht );
      pack.find( '.selectpicker' ).selectpicker( 'refresh' );
    } );
  }

  /* ====== * 微博私信选择 * ====== */
  function sina_destina( verified ) {
    if ( verified ) {
      $( 'select.send_destina' ).empty().append( '<option value="send_microblog">发微博</option><option value="send_letter">发私信</option>' );
      if ( util.getUrlParam( 'send_type' ) == 'private' ) {
        $( 'select.send_destina' ).val( 'send_letter' );
        pack.find( '.mass_select .sina_user_group' ).removeClass( 'hide' );
        pack.find( '.mass_select .sina_visible' ).addClass( 'hide' );
        type_nav.find( 'a:nth-child(3),a:last' ).addClass( 'hide' );
        type_nav.find( "a:first" ).trigger( 'click' );
        pack.find( '.mass_button > button.send_out' ).text( '分发' );
        pack.find( '.developer_tips' ).removeClass( 'hide' );
        sina_group();
      }

      if ( eitd_send.sina_type == 'message' ) {
        $( 'select.send_destina' ).val( 'send_letter' );
        sina_group();
      }
    } else {
      $( 'select.send_destina' ).empty().append( '<option value="send_microblog">发微博</option>' );
      if ( util.getUrlParam( 'send_type' ) == 'private' ) {
        message.show( '未认证微博号不支持分发私信', 500 );
      }
    }
    $( '.selectpicker' ).selectpicker( 'refresh' );
  }

  /* ====== * 微博私信与微博切换 * ====== */
  pack.find( '.send_destina' ).change( function() {
    var val = $( this ).val();
    type_nav.find( 'a' ).removeClass( 'hide' );
    if ( val == 'send_letter' ) {
      pack.find( '.mass_select .sina_user_group' ).removeClass( 'hide' );
      pack.find( '.mass_select .sina_visible' ).addClass( 'hide' );
      type_nav.find( 'a' ).not( ':nth-child(1),:nth-child(2)' ).addClass( 'hide' );
      type_nav.find( "a:first" ).trigger( 'click' );
      if ( send_data.index == 0 ) {
        pack.find( '.mass_button > button.send_out' ).text( '分发' );
      }
      pack.find( '.developer_tips' ).removeClass( 'hide' );
      sina_group();
    } else {
      pack.find( '.mass_select .sina_user_group' ).addClass( 'hide' );
      pack.find( '.mass_select .sina_visible' ).removeClass( 'hide' );
      type_nav.find( 'a' ).not( ':nth-child(2),:nth-child(3)' ).addClass( 'hide' );
      type_nav.find( "a" ).eq( 1 ).click();
      pack.find( '.developer_tips' ).addClass( 'hide' );
      if ( send_data.index == 0 ) {
        pack.find( '.mass_button > button.send_out' ).text( '发布' );
      }
    }
    if ( send_data.index == 1 ) {
      trip_ajax( send_data );
    }
  } );


  function sina_group() {
    $.ajax( {
      type: 'post',
      dataType: 'json',
      url: InterFace.WEIBO_INTERFACE.GET_GROUP,
      data: {
        uid: acount_info.uid
      },
      success: function( data ) {
        var data = typeof data === 'string' ? $.parseJSON( data ) : data;
        if ( data.ret == 0 ) {
          var option_nr = '',
            argument = data.data;
          for ( i in argument ) {
            if ( i != 'time' ) {
              option_nr += '<option value="' + argument[ i ].group_id + '">' + argument[ i ].group_name + '</option>'
            }
          }
          pack.find( '.mass_select select.sina_user_group' ).empty().append( option_nr );
          pack.find( '.selectpicker' ).selectpicker( 'refresh' );
        } else if ( data.ret == 40229 ) {
          $( '#send_developer' ).modal( 'show' );
        } else {
          message.showWarning( data.msg, showTime );
        }
      }
    } );
  }

  /* ====== * 分发方式切换 * ====== */
  function nav_box() {
    pack.find( ".nav_box" ).lavalamp( {
      speed: 300,
      click: function( e, ts ) {
        var index = $( ts ).index();
        send_data.index = index;
        $( '.mass_once, .mass_timing' ).slideToggle();

        ( index == 1 && send_data.pt == 'weixin' ) ? ( mass_content.find( 'li:first() a' ).eq( 1 ).attr( "href", "../edit_text?edit_sign=1" ) ) : ( mass_content.find( 'li:first() a' ).eq( 1 ).attr( "href", "../edit_text" ) );

        if ( index == 1 ) {
          pack.find( '.mass_select' ).removeClass( 'hide' );
          pack.find( '.mass_select .sel_time' ).removeClass( 'hide' );
          pack.find( '.mass_button > button.send_out' ).text( '保存此消息' );
          if ( eitd_send.first ) {
            loadTime( new Date( Date.parse( eitd_send.time ) ) );
          } else {
            loadTime( new Date( new Date().getTime() + 15 * 60 * 1000 ) );
          }
          rl_time();
        } else {
          pack.find( '.mass_select .sel_time' ).addClass( 'hide' );
          if ( send_data.pt == 'weixin' ) {
            pack.find( '.mass_button > button.send_out' ).text( '分发' );
          } else if ( send_data.pt == 'sina' ) {
            pack.find( '.mass_button > button.send_out' ).text( '发布' );
          } else if ( send_data.pt == 'toutiao' ) {
            pack.find( '.mass_button > button.send_out' ).text( '分发' );
            pack.find( '.mass_select' ).addClass( 'hide' );
          }
          status_record();
          pack.find( "#user_group" ).val( '' );
          pack.find( "#user_group" ).selectpicker( 'refresh' );
          multi_push.removeClass( 'hide' );
        }
        pack.find( '.selectpicker' ).selectpicker( 'refresh' );
        if ( send_data.pt != 'weixin' && multi_push.find( '#male' ).is( ':checked' ) ) {
          push_acount();
        }
      }
    } );
  }

  /* ====== * 分发类型切换 * ====== */
  type_nav.find( 'a' ).click( function() {
    var $t = $( this );
    if ( $t.hasClass( 'green' ) ) {
      return;
    }
    var i = $t.index();
    $( this ).addClass( "green" ).siblings().removeClass( "green" );
    mass_content.find( 'li' ).removeClass( "indication" ).eq( i ).addClass( "indication" );
    multi_push.removeClass( 'hide' );
    switch ( i ) {
      case 0:
        pack.find( '.send_out' ).data( 'edittype', 'mpnews' ).attr( 'data-edittype', 'mpnews' );
        break;
      case 1:
        pack.find( '.send_out' ).data( 'edittype', 'text' ).attr( 'data-edittype', 'text' );
        break;
      case 2:
        pack.find( '.send_out' ).data( 'edittype', 'image' ).attr( 'data-edittype', 'image' );
        break;
      case 3:
        pack.find( '.send_out' ).data( 'edittype', 'voice' ).attr( 'data-edittype', 'voice' );
        multi_push.addClass( 'hide' );
        break;
      case 4:
        pack.find( '.send_out' ).data( 'edittype', 'video' ).attr( 'data-edittype', 'video' );
        break;
    }
    if ( multi_push.find( '#male' ).is( ':checked' ) && i != 3 ) {
      push_acount();
    }
  } );

  mass_content.find( ".text_edit" ).keyup( function() {
    var len = $( this ).val().length;
    if ( $( this ).hasClass( 'text_maxlen' ) ) {
      mass_content.find( "#text_num" ).html( len );
    } else {
      mass_content.find( "#img_text_num" ).html( len );
    }
  } );

  /* ====== * 定时列表、时间与日历初始化 * ====== */
  function rl_time() {
    if ( eitd_send.first ) {
      send_data.time = eitd_send.time.split( ' ' )[ 0 ];
    } else {
      send_data.time = formatDate( new Date() ).fullTime;
    }

    trip_ajax( send_data, function( ymd ) {
      /** calendar配置 **/
      $( ".trip_calendar" ).empty().fullCalendar( {
        header: {
          left: 'title prev,next',
          center: '',
          right: ''
        },
        editable: true,
        events: ymd,
        dayClick: function( dayDate, allDay, jsEvent, view ) { //点击单元格事件
          if ( $( this ).hasClass( 'fc-other-month' ) ) {
            return;
          }
          loadTime( new Date( new Date().getTime() + 15 * 60 * 1000 ) );
          send_data.time = $.fullCalendar.formatDate( dayDate, "yyyy-MM-dd" );
          trip_ajax( send_data );
          $( ".calendar_date" ).val( send_data.time );
          $( ".fc-day.fc-state-highlight" ).removeClass( "fc-state-highlight" );
          $( this ).addClass( "fc-state-highlight" );
          $( '.event-inner[date]' ).removeAttr( "style" );
          $( '[date="' + send_data.time + '"]' ).css( {
            'background-color': '#fff'
          } );
        }
      } );
      /** 绑定事件到日期下拉框 **/
      $( function() {
        $( "#fc-dateSelect" ).delegate( "select", "change", function() {
          var fcsYear = $( "#fcs_date_year" ).val();
          var fcsMonth = $( "#fcs_date_month" ).val();
          $( ".trip_calendar" ).fullCalendar( 'gotoDate', fcsYear, fcsMonth );
        } );
      } );
      if ( eitd_send.first ) {
        eitd_send.first = false;
        var eitd_send_time = new Date( eitd_send.time );
        pack.find( '.trip_calendar' ).fullCalendar( 'gotoDate', eitd_send_time.format( 'yyyy' ), eitd_send_time.format( 'MM' ) * 1 - 1, eitd_send_time.format( 'dd' ) );

        pack.find( ".fc-state-highlight" ).removeClass( "fc-state-highlight" );
        $( "[data-date=" + eitd_send_time.format( 'yyyy-MM-dd' ) + "]" ).addClass( "fc-state-highlight" );
        $( "[date=" + eitd_send_time.format( 'yyyy-MM-dd' ) + "]" ).css( {
          backgroundColor: 'white'
        } );
      }
    } );
  }

  function trip_ajax( send_data, callback ) {
    var send_l_param = {
      time: send_data.time,
      callKBack: callback || '',
    }

    if ( send_data.pt == 'weixin' ) {
      $.ajax( {
        type: 'post',
        url: InterFace.SENDING.TIMER_LIST,
        data: {
          appid: acount_info.app_id,
          appointment_time: send_data.time,
          app: '微信',
        },
        success: function( data ) {
          var data = typeof data === 'string' ? $.parseJSON( data ) : data;
          send_l_param.data = data;
          send_l_param.pt = 'weixin';
          timing_list.init( send_l_param );
          if ( data.ret != 0 ) {
            message.showWarning( data.msg, showTime );
          }
        }
      } )
    } else if ( send_data.pt == 'sina' ) {
      if ( pack.find( '#send_destina' ).val() == 'send_letter' ) {
        var _url = InterFace.WEIBO_INTERFACE.LETTER_LIST
      } else {
        var _url = InterFace.WEIBO_INTERFACE.SEND_LIST
      }
      $.ajax( {
        type: 'post',
        dataType: 'json',
        url: _url,
        data: {
          uid: acount_info.uid,
          time: send_data.time,
        },
        success: function( data ) {
          var data = typeof data === 'string' ? $.parseJSON( data ) : data;
          send_l_param.data = data;
          send_l_param.pt = 'sina';
          timing_list.init( send_l_param );
          if ( data.ret != 0 ) {
            message.showWarning( data.msg, showTime );
          }
        }
      } );
    } else if ( send_data.pt == 'toutiao' ) {
      $.ajax( {
        type: 'post',
        url: InterFace.SENDING.TIME_ART_LIST,
        data: {
          uid: acount_info.uid,
          time: send_data.time,
        },
        success: function( data ) {
          var data = typeof data === 'string' ? $.parseJSON( data ) : data;
          send_l_param.data = data;
          send_l_param.pt = 'toutiao';
          timing_list.init( send_l_param );
          if ( data.ret != 0 ) {
            message.showWarning( data.msg, showTime );
          }
        }
      } )
    }
  }

  /* ====== * 分发素材选择 * ====== */
  mpnewsChoose.mpnewsChooseCallback = function( data ) {
    add_show( data.mpnewsArray, 'mpnews' );
    toutiao_mpnews( data.mpnewsArray );
  }
  imgChoose.imagesChooseCallback = function( data, data1 ) {
    add_show( data1, 'image' );
  }
  videoChoose.videoChooseCallback = function( data ) {
    add_show( data.videoObj, 'video' );
  }
  soundChoose.soundChooseCallback = function( data ) {
    add_show( data.soundObj, 'voice' );
  }

  /* ====== * 新建上传素材 * ====== */
  videoupload.doSave = function( data, data1 ) {
    add_show( data1, 'video' );
  }
  soundupload.doSave = function( data, data1 ) {
    add_show( data1, 'voice' );
  }
  imgupload.init( 'picture_upload', function( data ) {
    add_show( data, 'image' );
  } );

  function toutiao_mpnews( data ) {
    var html = '';
    for ( var i in data.articles ) {
      var arts = data.articles[ i ];
      html += '<div class="mpnews_info"><img src="' + util.imgTimthumb( arts.cover ) + '" alt=""><p>' + arts.title + '</p><div class="mask"><span class="glyphicon glyphicon-ok"></span></div></div>'
    }
    $( '#toutiao_mpnews .toutiao_mpnew_list' ).empty().append( html );
    if ( send_data.pt == 'toutiao' && data.articles.length > 1 ) {
      setTimeout( function() {
        $( '#toutiao_mpnews' ).modal( 'show' );
      }, 500 )
    }
  }

  function add_show( data, type ) {
    var data = typeof data === 'string' ? $.parseJSON( data ) : data;
    var html = '',
      json_s;
    if ( type == 'mpnews' ) {
      json_s = data;
      html += '<div class="add_show" data-id="' + json_s.article_group + '"><p>' + ( json_s.create_time || '' ) + '</p>';
      for ( var i in json_s.articles ) {
        if ( i == 0 ) {
          html += '' + constants.surpportHostName + '<div class="cover_info"><img src="/timthumb.php?w=300&src=" onerror="this.src=\'' + ( json_s.articles[ i ].cover || json_s.articles[ i ].image ) + '' + c.resPath + '/images/wuyulantu.png\';"/> <a href="javascript:void(0);">' + json_s.articles[ i ].title + '</a> </div>';
        } else {
          html += '<div class="art_info_more"><a href="javascript:void(0);">' + json_s.articles[ i ].title + '' + constants.surpportHostName + '</a> <img src="/timthumb.php?w=300&src=" onerror="this.src=\'' + ( json_s.articles[ i ].cover || json_s.articles[ i ].image ) + '' + c.resPath + '/images/wuyulantu.png\';"> </div>';
        }
      }
      html += '<a href="javascript:void(0);" class="delete">删除</a></div>';
    } else if ( type == 'image' ) {
      html += '<div class="add_show" data-imgname="' + data.image_name + '" data-imgid="' + ( send_data.pt == 'sina' ? data.image : data.image_id ) + '"><img src="' + util.imgTimthumb( data.image, 240 ) + '"><a href="javascript:void(0);" class="delete">删除</a></div>';
    } else if ( type == 'video' ) {
      html += '<div class="add_show" data-vid="' + data.video_id + '" data-adres="' + data.address + '" data-title="' + data.title + '" data-synopsis="' + data.synopsis + '"><video id="example_video_1" class="video-js vjs-default-skin" controls=""><source src="' + data.address + '"></video><a href="javascript:void(0);" class="delete">删除</a></div>';
    } else if ( type == 'voice' ) {
      html += '<div class="add_show" data-sid="' + data.voice_id + '" data-adres="' + data.address + '" data-title="' + data.title + '" ><div id="example_sound" class="clearfix"><div class="tubiao fl"><span class="iconfont icon-voice"></span></div><div class="wenb fr"><div class="biaot">' + data.title + '</div><div class="duration">' + data.length + '</div></div></div><a href="javascript:void(0);" class="delete">删除</a></div>';
    }

    if ( send_data.pt == 'sina' || util.getUrlParam( 'send_pltfm' ) == 'sina' ) {
      if ( type == 'image' ) {
        mass_content.find( 'li.indication .sina_imgxz' ).append( html ).children( 'a' ).addClass( 'hide' );
      } else {
        mass_content.find( 'li.indication' ).append( html ).find( '.add_content' ).addClass( 'hide' );
      }
    } else {
      mass_content.find( 'li.indication' ).append( html ).find( '.add_content' ).addClass( 'hide' );
    }
    if ( util.getUrlParam( 'pic_cd' ) ) {
      mass_content.find( 'li.indication .sina_imgxz' ).append( html ).children( 'a' ).addClass( 'hide' );
    }
  }

  function status_record() {
    var modify = pack.find( '.send_out' ).data( 'modify' );
    if ( modify ) {
      pack.find( '.delete_plan' ).removeAttr( "data-id" ).data( 'id', false ).addClass( 'hide' );
      pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
      mass_content.find( 'a.delete' ).trigger( 'click' );
      mass_content.find( '.text_edit' ).val( '' );
    }
  }

  /* ====== * 删除分发素材 * ====== */
  mass_content.on( 'click', '.delete', function() {
    var li = mass_content.find( 'li.indication' );
    $( this ).parents( ".add_show" ).remove();
    if ( li.index() == 2 ) {
      if ( send_data.pt == 'weixin' ) {
        li.find( '.add_content.weixin' ).removeClass( 'hide' );
      } else if ( send_data.pt == 'sina' ) {
        mass_content.find( 'li.indication .sina_imgxz' ).children( 'a' ).removeClass( 'hide' );
      }
    } else {
      li.find( '.add_content' ).removeClass( 'hide' );
    }
    var type = type_nav.find( 'a.green' ).index();
    if ( type == 0 && $( '.toutiao_mpnew_list' ).children().length > 1 ) {
      $( '#toutiao_mpnews .toutiao_mpnew_list' ).empty();
    }
  } );

  /* ====== * 分发 * ====== */
  pack.on( 'click', '.send_out', function() {
    if ( ( send_data.pt == 'toutiao' || $( '.push_toutiao .acount_info' ).hasClass( 'acount_choice' ) ) && type_nav.find( 'a.green' ).index() == 0 ) {
      if ( $( '.toutiao_mpnew_list' ).children().length > 1 && !$( '.toutiao_mpnew_list .mask' ).hasClass( 'active' ) ) {
        $( '#toutiao_mpnews' ).modal( 'show' );
        message.showWarning( '请选择头条分发图文', showTime );
        return;
      }
    }
    if ( pack.find( '#male' ).is( ':checked' ) ) {
      var n_k = '';
      var k = pack.find( '.multi_push .acount_info' ).length - 1;
      if ( send_data.pt == 'weixin' ) {
        n_k = k - $( '.push_weixin .acount_info' ).length;
      } else if ( send_data.pt == 'sina' ) {
        n_k = k - $( '.push_sina .acount_info' ).length;
      } else if ( send_data.pt == 'toutiao' ) {
        n_k = k - $( '.push_toutiao .acount_info' ).length;
      }

      if ( n_k > 0 && pack.find( '.multi_push .acount_info.acount_choice' ).length < 1 ) {
        message.showWarning( '请选择至少一个要分发的其他平台账号', showTime );
        return;
      };
    }
    var delivery_list = {};
    delivery_list.platf = send_data.pt;
    delivery_list.apid = ( send_data.pt == 'weixin' ) ? acount_info.app_id : acount_info.uid;
    delivery_list.acount = acount_info.login_account;
    delivery_list.verify = acount_info.verify_type_info;
    delivery( delivery_list );
    if ( pack.find( '#male' ).is( ':checked' ) ) {
      pack.find( '.multi_push .acount_info' ).each( function( i ) {
        if ( $( this ).hasClass( 'acount_choice' ) ) {
          var plat_aray = {};
          plat_aray.platf = $( this ).parents( '.push_plat' ).data( 'platf' );
          plat_aray.apid = $( this ).attr( 'appid' );
          plat_aray.acount = $( this ).attr( 'account' ) || '';
          plat_aray.verify = $( this ).attr( 'verify_info' ) || '';
          delivery( plat_aray );
          $( this ).removeClass( 'acount_choice' );
        }
        if ( i == k ) {
          mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
          pack.find( "#user_group" ).val( '' );
          pack.find( "#user_group" ).selectpicker( 'refresh' );
        }
      } )
    } else {
      mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
      pack.find( "#user_group" ).val( '' );
      pack.find( "#user_group" ).selectpicker( 'refresh' );
    }
  } );

  function delivery( data ) {
    var edittype = pack.find( '.send_out' ).data( 'edittype' );
    switch ( edittype ) {
      case 'mpnews':
        send_mpnews( data );
        break;
      case 'text':
        send_text( data );
        break;
      case 'image':
        send_imges( data );
        break;
      case 'video':
        send_video( data );
        break;
      case 'voice':
        send_voice( data );
        break;
    }
  }

  function send_mpnews( data ) {
    var platform = data.platf,
      app_id = data.apid,
      login_account = data.acount,
      verify = data.verify,
      news_id = mass_content.find( 'li.indication .add_show' ).data( 'id' ),
      articleTitle = mass_content.find( 'li.indication .add_show > .cover_info > a' ).text(),
      group_id = ( pack.find( '#user_group' ).val() == '全部用户' ) ? '' : pack.find( '#user_group' ).val(),
      sina_user_group = pack.find( '#sina_user_group' ).val(),
      modify = pack.find( '.send_out' ).data( 'modify' );
    if ( !news_id ) {
      message.show( "您没有选择图文！", showTime );
      return;
    }

    if ( platform == 'weixin' ) {
      if ( send_data.index == 0 ) {
        if ( verify == 0 ) {
          message.show( '正在分发…', 1500 );
          $.ajax( {
            type: 'post',
            url: InterFace.SENDING.ASYNSEND_SEND_ARTICLE,
            data: {
              app_id: app_id,
              article_group: news_id,
              group_id: group_id,
              title: articleTitle,
            },
            success: function( data ) {
              if ( data ) {
                var data = ( data && typeof data === 'string' ) ? $.parseJSON( data ) : data;
                if ( data.ret != 99999 ) {
                  message.showWarning( data.msg, showTime );
                }
              }
            }
          } );
        } else {
          var authorData = {
            login_account: login_account,
            appid: app_id
          }
          if ( !login_account ) {
            authorData.isNewAuthor = true;
          }
          bwAuthor.doAuthorOperate( authorData, function( data ) {
            login_account = data.login_account;
            message.show( '正在分发…', 1500 );
            $.ajax( {
              type: 'post',
              url: InterFace.SENDING.ASYNSIMSEND_SEND_ARTICLE,
              data: {
                login_account: login_account,
                article_group: news_id,
                group_id: group_id,
                title: articleTitle,
              },
              success: function( data ) {
                if ( data ) {
                  var data = typeof data === 'string' ? $.parseJSON( data ) : data;
                  if ( data.ret != 99999 ) {
                    message.showWarning( data.msg, showTime );
                  }
                }
              }
            } );
          } );
        }
      } else {
        var rtnTime = $.rtnTime();
        if ( !rtnTime ) {
          return;
        }
        if ( !modify ) {
          message.show( '正在储存' );
          $.ajax( {
            type: 'get',
            url: InterFace.SENDING.TIME_SEND,
            data: {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'mpnews',
              res: news_id,
              user_group: group_id,
            },
            success: function( data ) {
              var data = typeof data === 'string' ? $.parseJSON( data ) : data;
              if ( data.ret == 0 ) {
                message.show( '储存完毕', showTime );
                mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              } else {
                message.show( data.msg, showTime );
              }
              send_data.time = pack.find( ".mass_select .calendar_date" ).val();
              trip_ajax( send_data );
            }
          } )
        } else {
          $.ajax( {
            type: 'get',
            dataType: "json",
            url: InterFace.SENDING.EDIT_LOG,
            data: {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'mpnews',
              res: news_id,
              user_group: group_id,
              lid: modify,
            },
            success: function( data ) {
              if ( data.ret == 0 ) {
                trip_ajax( send_data );
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
                message.show( '修改完成！', 1000 );
                trip_ajax( send_data );
                mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              } else {
                message.show( data.msg, 1000 );
              }
            }
          } )
        }
      }
    } else if ( platform == 'sina' ) {
      if ( send_data.index == 0 ) {
        message.show( '正在分发...', showTime );
        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.WEIBO_INTERFACE.SEND_MESSAGE,
          data: {
            uid: app_id,
            group_id: sina_user_group,
            type: 'articles',
            cd: news_id,
          },
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret != 99999 ) {
              message.showWarning( data.msg, showTime );
            } else {
              message.hide();
            }
          }
        } );
      } else {
        var rtnTime = $.rtnTime();
        if ( !rtnTime ) {
          return;
        }
        var edit_id = ( !modify ) ? '' : modify;
        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.WEIBO_INTERFACE.TIME_SEND_MESSAGE,
          data: {
            uid: app_id,
            group_id: sina_user_group,
            type: 'articles',
            cd: news_id,
            send_time: rtnTime,
            id: edit_id,
          },
          success: function( data ) {
            if ( data.ret == 0 ) {
              message.show( '保存成功', showTime );
              if ( modify ) {
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
              }
              trip_ajax( send_data );
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
            } else {
              message.showWarning( data.msg, showTime );
            }
          }
        } );
      }
    } else if ( platform == 'toutiao' ) {
      var article_sort = 0;
      if ( $( '.toutiao_mpnew_list' ).children().length > 1 ) {
        article_sort = $( '.toutiao_mpnew_list .mask.active' ).parent().index();
      }
      if ( send_data.index == 0 ) {
        message.show( '正在分发...', showTime );
        $.ajax( {
          type: 'post',
          url: InterFace.SENDING.TOUTIAO_SEND_ARTICLE,
          data: {
            uid: app_id,
            group_cd: news_id,
            article_sort: article_sort,
          },
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret != 0 ) {
              message.showWarning( data.msg, showTime );
            }
          }
        } )
      } else {
        var rtnTime = $.rtnTime();
        if ( !rtnTime ) {
          return;
        }
        var edit_id = ( !modify ) ? '' : modify;
        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.SENDING.TOUTIAO_TIME_SEND_ARTICLE,
          data: {
            uid: app_id,
            group_cd: news_id,
            send_time: rtnTime,
            id: edit_id,
          },
          success: function( data ) {
            if ( data.ret == 0 ) {
              message.show( '保存成功', showTime );
              if ( modify ) {
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
              }
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              trip_ajax( send_data );
            } else {
              message.showWarning( data.msg, showTime );
            }
          }
        } );
      }
    }
  }

  function send_text( data ) {
    var platform = data.platf,
      app_id = data.apid,
      login_account = data.acount,
      verify = data.verify,
      group_id = ( pack.find( '#user_group' ).val() == '全部用户' ) ? '' : pack.find( '#user_group' ).val(),
      sina_user_group = pack.find( '#sina_user_group' ).val(),
      content = mass_content.find( 'li.indication .text_edit' ).val(),
      modify = pack.find( '.send_out' ).data( 'modify' ),
      visible = pack.find( 'select.sina_visible' ).val();

    if ( !app_id && login_account ) {
      message.show( "登录授权的分发方式暂不支持文字哦！", showTime );
      return;
    }
    if ( !app_id ) {
      message.show( "您没有选择公众号！", showTime );
      return;
    }
    if ( !content ) {
      message.show( "您没有输入文本内容！", showTime );
      return;
    }
    if ( platform == 'weixin' ) {
      if ( send_data.index == 0 ) {
        if ( verify == 0 ) {
          message.show( '正在分发' );
          $.ajax( {
            type: 'post',
            url: InterFace.SENDING.WECHAT_ASYNSEND_TEXT,
            data: {
              app_id: app_id,
              group_id: group_id,
              done: "text",
              content: content,
            },
            success: function( data ) {
              var data = typeof data === 'string' ? $.parseJSON( data ) : data;
              if ( data.ret == 0 ) {
                message.show( '分发状态:' + data.msg, showTime );
                mass_content.find( 'li.indication .text_edit' ).val( '' );
                pack.find( '#user_group' ).val( '' );
                pack.find( '#user_group' ).selectpicker( 'refresh' );
              } else {
                message.showWarning( '分发状态:' + data.msg, showTime );
              }
            }
          } )
        } else {
          var authorData = {
            login_account: login_account,
            appid: app_id
          }
          if ( !login_account ) {
            authorData.isNewAuthor = true;
          }
          bwAuthor.doAuthorOperate( authorData, function( data ) {
            acount_info.login_account = data.login_account;
            $.ajax( {
              type: 'post',
              url: InterFace.SENDING.WECHAT_SIM_SEND_TEXT,
              data: {
                login_account: acount_info.login_account,
                group_id: group_id,
                done: "text",
                content: content,
              },
              success: function( data ) {
                if ( data.errcode == '1' ) {
                  $( '#send_failed' ).modal();
                } else {
                  message.show( data.msg, showTime );
                  mass_content.find( 'li.indication .text_edit' ).val( '' );
                  pack.find( '#user_group' ).val( '' );
                  pack.find( '#user_group' ).selectpicker( 'refresh' );
                }
              }
            } );
          } );
        }
      } else {
        var rtnTime = $.rtnTime();
        if ( !rtnTime ) {
          return;
        }
        if ( !modify ) {
          message.show( '正在储存' );
          $.get( '/Timer/time_send', {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'text',
              res: content,
              user_group: group_id,
            },
            function( data ) {
              var data = typeof data === 'string' ? $.parseJSON( data ) : data;
              if ( data.ret == 0 ) {
                message.show( '储存完毕', showTime );
              } else {
                message.showWarning( data.msg, showTime );
              }
              send_data.time = pack.find( ".mass_select .calendar_date" ).val();
              trip_ajax( send_data );
              mass_content.find( 'li.indication .text_edit' ).val( '' );
              pack.find( '#user_group' ).val( '' );
              pack.find( '#user_group' ).selectpicker( 'refresh' );
            } )
        } else {
          $.ajax( {
            type: 'get',
            dataType: "json",
            url: InterFace.SENDING.EDIT_LOG,
            data: {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'text',
              res: content,
              user_group: group_id,
              lid: modify,
            },
            success: function( data ) {
              if ( data.ret == 0 ) {
                trip_ajax( send_data );
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
                mass_content.find( ".text_edit" ).val( '' );
                message.show( '修改完成！', 1000 );
                mass_content.find( 'li.indication .text_edit' ).val( '' );
                pack.find( '#user_group' ).val( '' );
                pack.find( '#user_group' ).selectpicker( 'refresh' );
              } else {
                message.showWarning( data.msg, 1000 );
              }
            }
          } )
        }
      }
    } else if ( platform == 'sina' ) {
      if ( send_data.index == 0 ) {
        if ( pack.find( '#send_destina' ).val() == 'send_letter' ) {
          $.ajax( {
            type: 'post',
            dataType: 'json',
            url: InterFace.WEIBO_INTERFACE.SEND_MESSAGE,
            data: {
              uid: app_id,
              type: 'text',
              group_id: sina_user_group,
              content: content,
            },
            complete: function( data ) {
              message.show( '正在分发...', showTime );
              mass_content.find( 'li.indication .text_edit' ).val( '' );
            }
          } );
        } else {
          $.ajax( {
            type: 'post',
            dataType: 'json',
            url: InterFace.WEIBO_INTERFACE.SEND_IMMEDIATE,
            data: {
              uid: app_id,
              visible: visible,
              content: content
            },
            success: function( data ) {
              if ( data.ret == 0 ) {
                message.show( '发布成功', showTime );
                mass_content.find( 'li.indication .text_edit' ).val( '' );
              } else {
                message.showWarning( data.msg, showTime );
              }
            }
          } );
        }
      } else {
        var rtnTime = $.rtnTime();
        if ( !rtnTime ) {
          return;
        }
        if ( pack.find( '#send_destina' ).val() == 'send_letter' ) {
          var exit_id = ( !modify ) ? '' : modify;
          message.show( '正在储存' );
          $.ajax( {
            type: 'post',
            dataType: 'json',
            url: InterFace.WEIBO_INTERFACE.TIME_SEND_MESSAGE,
            data: {
              uid: app_id,
              group_id: sina_user_group,
              type: 'text',
              content: content,
              send_time: rtnTime,
              id: exit_id,
            },
            success: function( data ) {
              if ( data.ret == 0 ) {
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).removeAttr( "data-id" ).data( 'id', false );
                mass_content.find( ".text_edit" ).val( '' );
                message.show( '保存成功', showTime );
                trip_ajax( send_data );
              } else {
                message.showWarning( data.msg, showTime );
              }
            }
          } );
        } else {
          var exit_id = ( !modify ) ? '' : modify;
          message.show( '正在储存' );
          $.ajax( {
            type: 'post',
            dataType: 'json',
            url: InterFace.WEIBO_INTERFACE.SEND_TIMING,
            data: {
              uid: app_id,
              visible: visible,
              content: content,
              time: rtnTime,
              id: exit_id,
            },
            success: function( data ) {
              if ( data.ret == 0 ) {
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
                mass_content.find( ".text_edit" ).val( '' );
                message.show( '保存成功', showTime );
                trip_ajax( send_data );
              } else {
                message.showWarning( data.msg, showTime );
              }
            }
          } );
        }
      }
    }
  }

  function send_imges( data ) {
    var platform = data.platf,
      app_id = data.apid,
      login_account = data.acount,
      verify = data.verify || '',
      group_id = ( pack.find( '#user_group' ).val() == '全部用户' ) ? '' : pack.find( '#user_group' ).val(),
      image_name = mass_content.find( 'li.indication .add_show' ).data( 'imgname' ),
      image_id = mass_content.find( 'li.indication .add_show' ).data( 'imgid' ),
      content = pack.find( 'li.indication .sina .text_edit' ).val(),
      modify = pack.find( '.send_out' ).data( 'modify' ),
      visible = pack.find( 'select.sina_visible' ).val();

    if ( !app_id && login_account ) {
      message.show( "登录授权的分发方式暂不支持图片哦！", showTime );
      return;
    }
    if ( !app_id ) {
      message.show( "您没有选择公众号！", showTime );
      return;
    }

    if ( !image_id ) {
      message.show( "您没有选择图片！", showTime );
      return;
    }
    if ( !content ) {
      content = '分享图片'
    }

    if ( platform == 'weixin' ) {
      if ( send_data.index == 0 ) {
        if ( verify == 0 ) {
          message.show( '正在分发', 500 );
          $.ajax( {
            type: 'post',
            url: InterFace.SENDING.WECHAT_ASYNSEND_IMAGE,
            data: {
              app_id: app_id,
              group_id: group_id,
              done: "image",
              image_name: image_name,
              image_id: image_id,
            },
            success: function( data ) {
              if ( data ) {
                var data = ( data && typeof data === 'string' ) ? $.parseJSON( data ) : data;
                if ( data.ret != 99999 ) {
                  message.showWarning( data.msg, showTime );
                }
              }
            },
            complete: function() {
              pack.find( "#user_group" ).val( '' );
              pack.find( "#user_group" ).selectpicker( 'refresh' );
            }
          } )
        } else {
          var authorData = {
            login_account: login_account,
            appid: app_id
          }
          if ( !login_account ) {
            authorData.isNewAuthor = true;
          }
          bwAuthor.doAuthorOperate( authorData, function( data ) {
            acount_info.login_account = data.login_account;
            $.ajax( {
              type: 'post',
              url: InterFace.SENDING.WECHAT_SIM_SEND_IMAGE,
              data: {
                login_account: acount_info.login_account,
                group_id: group_id,
                // done: "image",
                image_name: image_name,
                image: image_id,
              },
              success: function( data ) {
                if ( data.errcode == '1' ) {
                  $( '#send_failed' ).modal();
                } else {
                  message.show( data.msg, showTime );
                  pack.find( "#user_group" ).val( '' );
                  pack.find( "#user_group" ).selectpicker( 'refresh' );
                }
              }
            } );
          } );
        }
      } else {
        var rtnTime = $.rtnTime();
        if ( !rtnTime ) {
          return;
        }
        if ( !modify ) {
          message.show( '正在储存' );
          $.get( '/Timer/time_send', {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'image',
              res: image_id,
              user_group: group_id,
            },
            function( data ) {
              var data = typeof data === 'string' ? $.parseJSON( data ) : data;
              if ( data.ret == 0 ) {
                message.show( '储存完毕', showTime );
              } else {
                message.show( data.msg, showTime );
              }
              send_data.time = pack.find( ".mass_select .calendar_date" ).val();
              trip_ajax( send_data );
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
            } );
        } else {
          $.ajax( {
            type: 'get',
            dataType: "json",
            url: InterFace.SENDING.EDIT_LOG,
            data: {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'image',
              res: image_id,
              user_group: group_id,
              lid: modify,
            },
            success: function( data ) {
              if ( data.ret == 0 ) {
                trip_ajax( send_data );
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
                message.show( '修改完成！', 1000 );
                mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              } else {
                message.show( data.msg, 1000 );
              }
            }
          } )
        }
      }
    } else if ( platform == 'sina' ) {
      if ( send_data.index == 0 ) {
        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.WEIBO_INTERFACE.SEND_IMMEDIATE,
          data: {
            uid: app_id,
            img: image_id,
            visible: visible,
            content: content,
          },
          success: function( data ) {
            if ( data.ret == 0 ) {
              message.show( '发布成功', showTime );
              mass_content.find( 'li.indication .sina a.delete' ).trigger( 'click' );
            } else {
              message.showWarning( data.msg, showTime );
            }
          }
        } );
      } else {
        var rtnTime = $.rtnTime();
        if ( !rtnTime ) {
          return;
        }
        var exit_id = ( !modify ) ? '' : modify;
        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.WEIBO_INTERFACE.SEND_TIMING,
          data: {
            uid: app_id,
            visible: visible,
            content: content,
            img: image_id,
            time: rtnTime,
            id: exit_id,
          },
          success: function( data ) {
            if ( data.ret == 0 ) {
              pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
              pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
              mass_content.find( ".text_edit" ).val( '' );
              message.show( '保存成功', showTime );
              trip_ajax( send_data );
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
            } else {
              message.showWarning( data.msg, showTime );
            }
          }
        } );
      }
    }
  }

  function send_video( data ) {
    var platform = data.platf,
      app_id = data.apid,
      login_account = data.acount,
      group_id = ( pack.find( '#user_group' ).val() == '全部用户' ) ? '' : pack.find( '#user_group' ).val(),
      video_id = mass_content.find( 'li.indication .add_show' ).data( 'vid' ),
      title = mass_content.find( 'li.indication .add_show' ).data( 'title' ),
      adres = mass_content.find( 'li.indication .add_show' ).data( 'adres' ),
      synopsis = mass_content.find( 'li.indication .add_show' ).data( 'synopsis' ),
      modify = pack.find( '.send_out' ).data( 'modify' );

    if ( !app_id && login_account ) {
      message.show( "登录授权的分发方式暂不支持视频哦！", showTime );
      return;
    }

    if ( !video_id ) {
      message.show( "您没有选择视频！", showTime );
      return;
    }
    if ( send_data.index == 0 ) {
      message.show( '正在分发' );
      if ( platform == 'weixin' ) {
        $.ajax( {
          type: 'post',
          url: InterFace.SENDING.WECHAT_ASYNSEND_VIDEO,
          data: {
            app_id: app_id,
            done: "video",
            group_id: group_id,
            video_id: video_id,
          },
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret == 0 ) {
              pack.find( "#user_group" ).val( '' );
              pack.find( "#user_group" ).selectpicker( 'refresh' );
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
            }
            message.show( '分发状态:' + data.msg, showTime );
          }
        } )
      } else {
        $.ajax( {
          type: 'post',
          url: InterFace.SENDING.TOUTIAO_SEND_VIDEO,
          data: {
            uid: app_id,
            video: adres,
            title: title,
            abstract: synopsis,
          },
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret != 99999 ) {
              message.showWarning( data.msg, showTime );
            } else {
              message.hide();
            }
          },
          complete: function() {
            message.hide();
          }
        } )
      }
    } else {
      var rtnTime = $.rtnTime();
      if ( !rtnTime ) {
        return;
      }
      if ( platform == 'weixin' ) {
        if ( !modify ) {
          message.show( '正在储存' );
          $.get( InterFace.SENDING.TIME_SEND, {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'video',
              res: video_id,
              user_group: group_id,
            },
            function( data ) {
              var data = typeof data === 'string' ? $.parseJSON( data ) : data;
              if ( data.ret == 0 ) {
                message.show( '储存完毕', showTime );
                trip_ajax( send_data );
              } else {
                message.show( data.msg, showTime );
              }
            } )
        } else {
          $.ajax( {
            type: 'get',
            dataType: "json",
            url: InterFace.SENDING.EDIT_LOG,
            data: {
              timeSend: rtnTime,
              appid: app_id,
              msg_type_cd: 'video',
              res: video_id,
              user_group: group_id,
              lid: modify,
            },
            success: function( data ) {
              if ( data.ret == 0 ) {
                trip_ajax( send_data );
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
                message.show( '修改完成！', 1500 );
              } else {
                message.show( data.msg, 1500 );
              }
            }
          } )
        }
      } else if ( platform == 'toutiao' ) {
        var edit_id = ( !modify ) ? '' : modify;
        $.ajax( {
          type: 'post',
          url: InterFace.SENDING.TOUTIAO_TIME_SEND_VIDEO,
          data: {
            uid: app_id,
            video: adres,
            title: title,
            abstract: synopsis,
            send_time: rtnTime,
            id: edit_id,
          },
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret == 0 ) {
              message.show( '保存成功', showTime );
              if ( modify ) {
                pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
                pack.find( '.delete_plan' ).removeAttr( "data-id" ).data( 'id', false );
              }
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              trip_ajax( send_data );
            } else {
              message.showWarning( data.msg, showTime );
            }
          }
        } )
      }
    }
  }

  function send_voice( data ) {
    var platform = data.platf,
      app_id = data.apid,
      group_id = ( pack.find( '#user_group' ).val() == '全部用户' ) ? '' : pack.find( '#user_group' ).val(),
      voice_id = mass_content.find( 'li.indication .add_show' ).data( 'sid' ),
      modify = pack.find( '.send_out' ).data( 'modify' ) || '';

    if ( !voice_id ) {
      message.show( "您没有选择语音！", showTime );
      return;
    }
    if ( send_data.index == 0 ) {
      message.show( '正在分发' );
      $.ajax( {
        type: 'post',
        url: InterFace.SENDING.WECHAT_ASYNSEND_VOICE,
        data: {
          app_id: app_id,
          group_id: group_id,
          voice_id: voice_id,
        },
        success: function( data ) {
          var data = typeof data === 'string' ? $.parseJSON( data ) : data;
          if ( data.ret != 99999 ) {
            message.showWarning( data.data, showTime );
          } else {
            message.show( '分发成功', showTime );
          }
        }
      } )
    } else {
      var rtnTime = $.rtnTime();
      if ( !rtnTime ) {
        return;
      }
      message.show( '正在保存...' );
      if ( modify ) {
        $.ajax( {
          type: 'get',
          url: InterFace.SENDING.EDIT_LOG,
          data: {
            appid: app_id,
            timeSend: rtnTime,
            msg_type_cd: 'voice',
            res: voice_id,
            group_id: group_id,
            lid: modify,
          },
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret == 0 ) {
              pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
              pack.find( '.delete_plan' ).addClass( 'hide' ).removeAttr( "data-id" ).data( 'id', false );
              message.show( '修改完成！', showTime );
              trip_ajax( send_data );
            } else {
              message.show( data.msg, showTime );
            }
          }
        } )
      } else {
        $.ajax( {
          type: 'get',
          url: InterFace.SENDING.TIME_SEND,
          data: {
            appid: app_id,
            timeSend: rtnTime,
            msg_type_cd: 'voice',
            res: voice_id,
            group_id: group_id,
            lid: modify,
          },
          success: function( data ) {
            var data = typeof data === 'string' ? $.parseJSON( data ) : data;
            if ( data.ret == 0 ) {
              message.show( '保存成功', showTime );
              trip_ajax( send_data );
            } else {
              message.show( data.msg, showTime );
            }
          }
        } )
      }

    }
  }

  var options = {
    category: {
      'mpnews': '1',
      'text': '2',
      'image': '3',
      'voice': '4',
      'video': '5',
    },
    gender: {
      '男': '1',
      '女': '2',
      '全部': '3'
    },
    ms: {
      '1': '已分发',
      '2': '待分发',
      '3': '分发失败',
      '4': '已删除'
    },
  };
  /* ====== * 定时分发修改 * ====== */
  pack.on( 'click', '.sub_info', function() {
    var $this = $( this ),
      timing_id = $this.data( 'timing-id' ),
      timing_cd = $this.data( 'timing-cd' ),
      timing_time = new Date( $this.data( 'timing-time' ).replace( /-/g, '/' ) ),
      timing_group = $this.find( ".info_group" ).data( 'group' ),
      send_type = $this.data( "send-type" ),
      new_time = Date.parse( new Date().format( 'yyyy/MM/dd hh:mm' ) ),
      cate = options.category[ send_type ];

    if ( 0 < ( Date.parse( timing_time ) - new_time ) / 1000 / 60 && ( Date.parse( timing_time ) - new_time ) / 1000 / 60 < 30 ) {
      message.showWarning( '不能编辑分发时间与当前时间差小于30分钟的分发消息!', message.showTime );
      return;
    }
    if ( $this.find( ".iconfont" ).hasClass( "icon-fangxiang" ) ) {
      pack.find( '.delete_plan' ).removeClass( 'hide' );
    } else {
      pack.find( '.delete_plan' ).addClass( 'hide' );
    }

    if ( type_nav.find( 'a.green' ).index() * 1 + '1' != cate ) {
      type_nav.find( 'a' ).eq( cate - 1 ).click();
    }

    var fcs_month = pack.find( '#fcs_date_month' ).val() * 1 + 1;
    ( fcs_month < 10 ) ? ( fcs_month = '0' + fcs_month ) : fcs_month;
    if ( timing_time.format( 'MM' ) != fcs_month ) {
      pack.find( '.trip_calendar' ).fullCalendar( 'gotoDate', timing_time.format( 'yyyy' ), timing_time.format( 'MM' ) * 1 - 1, timing_time.format( 'dd' ) )
    }

    pack.find( ".fc-state-highlight" ).removeClass( "fc-state-highlight" );
    $( "[data-date=" + timing_time.format( 'yyyy-MM-dd' ) + "]" ).addClass( "fc-state-highlight" );
    $( "[date=" + timing_time.format( 'yyyy-MM-dd' ) + "]" ).css( {
      backgroundColor: 'white'
    } );
    pack.find( ".calendar_date" ).val( timing_time.format( 'yyyy-MM-dd' ) );
    pack.find( "#select_hour" ).val( timing_time.format( 'hh' ) );
    pack.find( "#select_min" ).val( timing_time.format( 'mm' ) );
    pack.find( "#select_hour" ).selectpicker( 'refresh' );
    pack.find( "#select_min" ).selectpicker( 'refresh' );
    pack.find( ".delete_plan" ).attr( "data-id", timing_id ).data( 'id', timing_id );
    pack.find( ".send_out" ).attr( "data-modify", timing_id ).data( 'modify', timing_id );
    send_data.time = pack.find( ".mass_select .calendar_date" ).val();
    if ( send_data.pt == 'weixin' ) {
      pack.find( "#user_group" ).val( timing_group );
      pack.find( "#user_group" ).selectpicker( 'refresh' );
      if ( send_type == 'text' ) {
        var text = $this.find( 'p' ).text().split( '】' );
        mass_content.find( ".text_edit" ).focus().val( text[ 1 ] );
      } else {
        $.get(
          InterFace.SENDING.GET_ART_GROUP, {
            article_group: timing_cd,
            msg_type_cd: send_type
          },
          function( obj ) {
            var data = typeof obj === 'string' ? $.parseJSON( obj ) : obj;
            if ( data.ret == '80014' ) {
              message.showWarning( data.msg, 1500 );
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              return;
            }
            mass_content.find( "li.indication > .add_show" ).remove();
            mass_content.find( "li.indication > .add_content" ).addClass( 'hide' );
            mass_content.find( "li.indication" ).append( obj.content );
            if ( ( Date.parse( timing_time ) - new_time ) / 1000 / 60 < 30 ) {
              pack.find( '.add-show > a.delete' ).hide();
            }
          } );
      }
    } else if ( send_data.pt == 'sina' ) {
      pack.find( "#sina_visible" ).val( timing_group );
      pack.find( "#sina_visible" ).selectpicker( 'refresh' );
      if ( send_type == 'text' ) {
        var text = $this.find( 'p' ).text().split( '】' );
        mass_content.find( "li.indication .text_edit" ).focus().val( text[ 1 ] );
      } else if ( send_type == 'image' ) {
        var text = $this.find( 'p' ).text().split( '】' );
        mass_content.find( "li.indication .text_edit" ).focus().val( text[ 1 ] );
        var html = '<div class="add_show" data-imgid="' + timing_cd + '"><img src="' + timing_cd + '"><a href="javascript:void(0);" class="delete">删除</a></div>';
        mass_content.find( 'li.indication .add_show' ).remove();
        mass_content.find( 'li.indication .sina_imgxz' ).append( html ).children( 'a' ).addClass( 'hide' );
      } else if ( send_type == 'mpnews' ) {
        $.get(
          InterFace.SENDING.GET_ART_GROUP, {
            article_group: timing_cd,
            msg_type_cd: send_type
          },
          function( obj ) {
            mass_content.find( "li.indication > .add_show" ).remove();
            mass_content.find( "li.indication > .add_content" ).hide();
            mass_content.find( "li.indication" ).append( obj.content );
          } );
      }
    } else if ( send_data.pt == 'toutiao' ) {
      if ( send_type == 'mpnews' ) {
        $.get(
          InterFace.SENDING.GET_ART_GROUP, {
            article_group: timing_cd,
            msg_type_cd: send_type
          },
          function( obj ) {
            mass_content.find( "li.indication > .add_show" ).remove();
            mass_content.find( "li.indication > .add_content" ).hide();
            mass_content.find( "li.indication" ).append( obj.content );
          } );

      } else {
        $.get(
          InterFace.SENDING.GET_ART_GROUP, {
            article_group: timing_cd,
            msg_type_cd: send_type
          },
          function( obj ) {
            var html = '<div class="add_show" data-imgid="' + timing_id + '"><video class="video-js vjs-default-skin" controls style="width:100%;height:100%"><source src="' + timing_cd + '"/></video><a href="javascript:void(0);" class="delete">删除</a></div>';
            mass_content.find( 'li.indication .add_show' ).remove();
            mass_content.find( 'li.indication' ).append( html ).children( '.add_content' ).addClass( 'hide' );
          } );
      }
    }
  } ); /* ====== * 删除定时分发 * ====== */
  pack.on( 'click', ".delete_plan", function() {
    var $this = $( this );
    var lid = $this.data( "id" );
    if ( send_data.pt == 'weixin' ) {
      $.ajax( {
        type: 'post',
        url: InterFace.SENDING.DELETE_NEWS,
        dataType: 'json',
        data: {
          lid: lid
        },
        success: function( data ) {
          if ( data.ret == 0 ) {
            message.show( '删除成功！', 1000 );
            send_data.time = pack.find( ".mass_select .calendar_date" ).val();
            trip_ajax( send_data );
            if ( pack.find( '.send_out' ).data( 'edittype' ) == 'text' ) {
              mass_content.find( 'li.indication .text_edit' ).val( '' );
            } else {
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
            }
            $this.removeAttr( "data-id" ).data( 'id', false ).addClass( 'hide' );
            pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
          } else if ( data.ret == -1 ) {
            message.show( '删除失败！请重试！', 1000 );
          } else {
            message.show( '同步微信失败,请手动删除微信端记录！', 2000 );
            send_data.time = pack.find( ".mass_select .calendar_date" ).val();
            trip_ajax( send_data );
            if ( pack.find( '.send_out' ).data( 'edittype' ) == 'text' ) {
              mass_content.find( '.text_edit' ).val( '' );
            } else {
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
            }
            $this.removeAttr( "data-id" ).data( 'id', false ).addClass( 'hide' );
            pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
            if ( pack.find( '.send_out' ).is( ':hidden' ) ) {
              pack.find( '.send_out' ).show();
            }
          }
        }
      } );
    } else if ( send_data.pt == 'sina' ) {
      if ( pack.find( '#send_destina' ).val() == 'send_letter' ) {
        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.WEIBO_INTERFACE.LETTER_DELETE,
          data: {
            uid: acount_info.uid,
            id: lid,
          },
          success: function( data ) {
            if ( data.ret == 0 ) {
              message.show( '删除成功！', 1000 );
              send_data.time = pack.find( ".mass_select .calendar_date" ).val();
              trip_ajax( send_data );
              mass_content.find( 'li.indication .text_edit' ).val( '' );
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              $this.removeAttr( "data-id" ).data( 'id', false ).addClass( 'hide' );
              pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
            } else {
              message.showWarning( '删除失败！请重试！', 1000 );
            }
          }
        } );
      } else {
        $.ajax( {
          type: 'post',
          dataType: 'json',
          url: InterFace.WEIBO_INTERFACE.DELETE_TIMING,
          data: {
            uid: acount_info.uid,
            id: lid,
          },
          success: function( data ) {
            if ( data.ret == 0 ) {
              message.show( '删除成功！', 1000 );
              send_data.time = pack.find( ".mass_select .calendar_date" ).val();
              trip_ajax( send_data );
              mass_content.find( 'li.indication .text_edit' ).val( '' );
              mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
              $this.removeAttr( "data-id" ).data( 'id', false ).addClass( 'hide' );
              pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
            } else {
              message.showWarning( '删除失败！请重试！', 1000 );
            }
          }
        } );
      }
    } else if ( send_data.pt == 'toutiao' ) {
      $.ajax( {
        type: 'post',
        url: InterFace.SENDING.TIME_ART_DEL,
        data: {
          uid: acount_info.uid,
          id: lid,
        },
        success: function( data ) {
          var data = typeof data === 'string' ? $.parseJSON( data ) : data;
          if ( data.ret == 0 ) {
            message.show( '删除成功！', 1000 );
            send_data.time = pack.find( ".mass_select .calendar_date" ).val();
            trip_ajax( send_data );
            mass_content.find( 'li.indication a.delete' ).trigger( 'click' );
            $this.removeAttr( "data-id" ).data( 'id', false ).addClass( 'hide' );
            pack.find( '.send_out' ).removeAttr( "data-modify" ).data( 'modify', false );
          } else {
            message.showWarning( '删除失败！请重试！', 1000 );
          }
        }
      } )
    }
  } );

  /* ====== * 时间差是否小于30分钟 * ====== */
  $.extend( {
    rtnTime: function() {
      var rtnTime;
      var now = new Date().format( 'yyyy-MM-dd hh:mm' );
      var setDate = pack.find( '.calendar_date' ).val(),
        setHour = pack.find( '#select_hour' ).val(),
        setMin = pack.find( '#select_min' ).val(),
        time = setDate + " " + setHour + ":" + setMin;
      if ( Date.parse( time ) / 1000 <= Date.parse( now ) / 1000 ) {
        message.showWarning( "系统无法穿越回去分发消息哦！", showTime );
        rtnTime = false;
      } else {
        rtnTime = time;
      }
      return rtnTime;
    }
  } );

  /* ====== * 多平台分发 * ====== */
  var multi_push = pack.find( '.multi_push' );

  multi_push.on( 'click', '.acount_info', function() {
    var $this = $( this );
    if ( $this.hasClass( 'acount_choice' ) ) {
      $( this ).removeClass( 'acount_choice' );
    } else {
      $( this ).addClass( 'acount_choice' );
    }
  } );

  multi_push.on( 'click', '#male', function() {
    if ( $( this ).is( ':checked' ) ) {
      push_acount();
    } else {
      multi_push.find( '.push_plat' ).addClass( 'hide' );
    }
  } )

  function push_acount() {
    var type = type_nav.find( 'a.green' ).index();
    multi_push.removeClass( 'hide' );
    multi_push.find( '.push_plat' ).addClass( 'hide' );
    multi_push.find( '.acount_info' ).removeClass( 'acount_choice' );
    pack.find( '.push_sina .gray_c' ).addClass( 'hide' );

    if ( send_data.pt == 'weixin' ) {
      if ( type == 0 ) {
        multi_push.find( '.push_toutiao, .push_sina' ).removeClass( 'hide' );
        multi_push.find( '.push_sina .acount_info[verify_info="0"]' ).addClass( 'hide' );
        if ( multi_push.find( '.push_sina .acount_info[verify_info="1"]' ).length < 1 ) {
          pack.find( '.push_sina .gray_c' ).removeClass( 'hide' );
        }
      } else if ( type == 1 || type == 2 ) {
        multi_push.find( '.push_sina' ).removeClass( 'hide' );
        multi_push.find( '.push_sina .acount_info' ).removeClass( 'hide' );
      } else if ( type == 4 ) {
        multi_push.find( '.push_toutiao' ).removeClass( 'hide' );
      }
    } else if ( send_data.pt == 'sina' ) {
      multi_push.find( '.push_weixin' ).removeClass( 'hide' );
      if ( type == 0 ) {
        multi_push.find( '.push_toutiao' ).removeClass( 'hide' );
      }
    } else if ( send_data.pt == 'toutiao' ) {
      multi_push.find( '.push_weixin' ).removeClass( 'hide' );
      if ( type == 0 ) {
        multi_push.find( '.push_weixin, .push_sina' ).removeClass( 'hide' );
        multi_push.find( '.push_sina .acount_info[verify_info="0"]' ).addClass( 'hide' );
        if ( multi_push.find( '.push_sina .acount_info[verify_info="1"]' ).length < 1 ) {
          pack.find( '.push_sina .gray_c' ).removeClass( 'hide' );
        }
      }
    }
  }

  /* ====== * 多平台分发账号列表 * ====== */
  function multi_platform() {
    $.post( '/common/get_send_preview', {}, function( data ) {
      var html = '';
      var json = typeof data === 'string' ? $.parseJSON( data ) : data;
      if ( json.length == 0 ) {
        html = '<p class="gray_c">还未授权公众号，<a href="/my_account">立即授权</a></p>'
      } else {
        for ( var i in json ) {
          if ( json[ i ].verify_type_info == 0 ) {
            html += '<div class="acount_info" appid="' + json[ i ].app_id + '" verify_info="' + json[ i ].verify_type_info + '" account="' + json[ i ].login_account + '"> <img src="' + ( json[ i ].image || c.resPath + '/images/default_face.png' ) + '" alt="头像"> <p>' + json[ i ].user_name + '</p> </div>';
          }
        }
        if ( html == '' ) {
          html = '<p class="gray_c">您没有已经认证的公众号，<a href="/my_account">立即授权</a></p>'
        }
      }
      pack.find( '.push_weixin .account_number' ).empty().append( html );
    } );

    // 新浪
    $.post( "/sina/user_sina_list", {}, function( data ) {
      var html = '';
      var json = typeof data === 'string' ? $.parseJSON( data ) : data;
      if ( json.ret != 0 ) {
        html = '<p class="gray_c">还未授权新浪微博，<a href="/my_account?platform=sina">立即授权</a></p>'
      } else {
        for ( var i in json.data ) {
          html += '<div class="acount_info ' + ( !json.data[ i ].verified ? 'hide' : '' ) + '" appid="' + json.data[ i ].uid + '" verify_info="' + ( json.data[ i ].verified || 0 ) + '"> <img src="' + ( json.data[ i ].profile_image_url || c.resPath + '/images/default_face.png' ) + '" alt=""> <p>' + json.data[ i ].screen_name + '</p> </div>';
        }
      }

      pack.find( '.push_sina .account_number' ).empty().append( html + '<p class="gray_c hide">您没有已经认证的新浪微博号！</p>' );
    } );

    // 头条
    $.ajax( {
      type: 'post',
      url: '/toutiao/account_list',
      data: {},
      success: function( data ) {
        var html = '';
        var json = typeof data === 'string' ? $.parseJSON( data ) : data;
        if ( !json.data ) {
          html = '<p class="gray_c">还未授权头条账，<a href="/my_account?platform=toutiao">立即授权</a></p>'
        } else {
          for ( var i in json.data ) {
            html += '<div class="acount_info" appid="' + json.data[ i ].uid + '"><img src="' + ( json.data[ i ].avatar_url || c.resPath + '/images/default_face.png' ) + '" alt=""> <p>' + json.data[ i ].screen_name + '</p> </div>';
          }
        }
        pack.find( '.push_toutiao .account_number' ).empty().append( html );
      }
    } );
  };



  function loadTime( nowDate ) {
    var ret_date = formatDate( nowDate );
    var newHour = ret_date.nowHour;
    var newMin = ret_date.nowMin;
    if ( newMin % 5 != 0 ) {
      if ( newMin > 55 ) {
        newMin = '0' + 0;
        if ( ( parseInt( newHour ) + 1 ) < 10 ) {
          newHour = '0' + ( parseInt( newHour ) + 1 );
        } else if ( newHour == 23 ) {
          newHour = '0' + 0;
        } else {
          newHour = parseInt( newHour ) + 1;
        }
      } else {
        newMin = newMin - newMin % 5 + 5
      }
    }

    pack.find( ".mass_select .calendar_date" ).val( ret_date.fullTime );
    pack.find( ".mass_select #select_hour" ).val( newHour );
    pack.find( ".mass_select #select_min" ).val( newMin );

    pack.find( "#select_hour" ).trigger( 'change' );
    pack.find( "#select_min" ).trigger( 'change' );
    pack.find( "#select_hour" ).selectpicker( 'refresh' );
    pack.find( "#select_min" ).selectpicker( 'refresh' );
  }

  function formatDate( date ) {
    var nowYear = date.getFullYear();
    var nowMonth = date.getMonth() + 1;
    var nowDay = date.getDate();
    var nowHour = date.getHours();
    var nowMin = date.getMinutes();
    if ( nowMonth < 10 ) {
      nowMonth = "0" + nowMonth;
    }
    if ( nowDay < 10 ) {
      nowDay = "0" + nowDay;
    }
    if ( nowHour < 10 ) {
      nowHour = "0" + nowHour;
    }
    if ( nowMin < 10 ) {
      nowMin = "0" + nowMin;
    }
    return {
      nowYear: nowYear,
      nowMonth: nowMonth,
      nowDay: nowDay,
      nowHour: nowHour,
      nowMin: nowMin,
      week: date.getDay(),
      fullTime: nowYear + "-" + nowMonth + "-" + nowDay,
      fullDate: nowYear + "-" + nowMonth + "-" + nowDay + " " + nowHour + ":" + nowMin,
    };
  }

  $( '#toutiao_mpnews .toutiao_mpnew_list' ).on( 'click', '.mpnews_info', function() {
    $( this ).siblings().find( '.mask' ).removeClass( 'active' );
    $( this ).find( '.mask' ).addClass( 'active' );
  } )
} );
